package org.jimm.ui;

import java.util.List;

import org.jimm.app.R;
import org.jimm.data.IconMenu;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public final class MenuAdapter extends ArrayAdapter<IconMenu> {
	private List<IconMenu> iconMenu;
	private LayoutInflater inflater;
	
	public MenuAdapter(Activity context, List<IconMenu> iconMenu) {
		super(context, R.layout.menu_item, iconMenu);
		
		this.iconMenu = iconMenu;
		this.inflater = context.getLayoutInflater();	
	}
	
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ItemViewHolder itemViewHolder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.menu_item, parent, false);
			itemViewHolder = new ItemViewHolder();
			itemViewHolder.labelTextView = (TextView) convertView.findViewById(R.id.text_item);
			itemViewHolder.iconImage = (ImageView) convertView.findViewById(R.id.icon_item);
			convertView.setTag(itemViewHolder);
		} else {
			itemViewHolder = (ItemViewHolder) convertView.getTag();
		}
		
		
		itemViewHolder.labelTextView.setText(iconMenu.get(position).title);
		itemViewHolder.iconImage.setImageResource(iconMenu.get(position).bigIconId);

		return convertView;
	}
	
	private class ItemViewHolder {
		public TextView labelTextView;
		public ImageView iconImage;
	}
}